/**
 * FormOrcamento.java
 * Copyright (C) 2009 Jose Mauro da Silva Sandy
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * FormOrcamento.java
 *
 * Created on 10/05/2009, 01:15:50
 */

package frames;

import java.io.IOException;
import java.text.*;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import negocio.notas.Orcamento;
import negocio.pessoas.Pessoa;
import utils.*;
/**
 *
 * @author jmsandy
 */
public class FormOrcamento extends javax.swing.JDialog {

    //<editor-fold defaultstate="collapsed" desc="FIELDS">
    private Orcamento orcamento   = null;
    private Pessoa    fornecedor = null;
    private ArrayList lstObj      = null;
    private int posicao           = 0;
    private int situacao          = 0;
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Constants">
    private static final int K_FIELDS_BUSCA   = 1;
    private static final int K_FIELDS_NOVO    = 2;
    private static final int K_FIELDS_SALVAR  = 3;
    public static final int K_FORM_CADASTRO   = 4;
    public static final int K_FORM_PESQUISA   = 5;
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Acessores">
    public Orcamento getOrcamento(){
        return this.orcamento;
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Constructors">
    /** Creates new form FormOrcamento */
    public FormOrcamento() {
        initComponents();
        initializeMyComponents();
    }
    public FormOrcamento(Integer tipo){
        initComponents();
        initializeMyComponents();
        this.situacao = tipo;
    }
    //</editor-fold>

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormOrcamento().setVisible(true);
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panel = new javax.swing.JPanel();
        lbNumOrcamento = new javax.swing.JLabel();
        lbNumOrcFunc = new javax.swing.JLabel();
        lbDataOrcamento = new javax.swing.JLabel();
        lbDataValidade = new javax.swing.JLabel();
        lbFornecedor = new javax.swing.JLabel();
        textFornecedor = new javax.swing.JTextField();
        lbValorTotal = new javax.swing.JLabel();
        textValorTotal = new javax.swing.JTextField();
        textDtOrcamento = new javax.swing.JFormattedTextField();
        textNumOrc = new javax.swing.JTextField();
        textNumOrcFornc = new javax.swing.JTextField();
        textDtValidade = new javax.swing.JFormattedTextField();
        btnFornecedor = new javax.swing.JButton();
        panelBotao = new javax.swing.JPanel();
        btnBuscar = new javax.swing.JButton();
        btnNovo = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        btnExcluir = new javax.swing.JButton();
        jPanelNavegacao = new javax.swing.JPanel();
        btnFirst = new javax.swing.JButton();
        btnPrevious = new javax.swing.JButton();
        btnNext = new javax.swing.JButton();
        btnLast = new javax.swing.JButton();

        setTitle("Orçamento");
        setModal(true);
        setName("formOrcamento"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        panel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        panel.setFont(new java.awt.Font("SansSerif", 0, 12));

        lbNumOrcamento.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbNumOrcamento.setText("*Nº Orçamento");

        lbNumOrcFunc.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbNumOrcFunc.setText("Nº Orçamento Fornecedor");

        lbDataOrcamento.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbDataOrcamento.setText("*Data Orçamento");

        lbDataValidade.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbDataValidade.setText("Data Validade");

        lbFornecedor.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbFornecedor.setText("*Fornecedor");

        textFornecedor.setBackground(java.awt.Color.white);
        textFornecedor.setEditable(false);
        textFornecedor.setFont(new java.awt.Font("SansSerif", 0, 12));
        textFornecedor.setPreferredSize(new java.awt.Dimension(200, 26));

        lbValorTotal.setFont(new java.awt.Font("SansSerif", 0, 12));
        lbValorTotal.setText("*Valor Total");

        textValorTotal.setBackground(java.awt.Color.white);
        textValorTotal.setEditable(false);
        textValorTotal.setFont(new java.awt.Font("SansSerif", 0, 12));
        textValorTotal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        textValorTotal.setPreferredSize(new java.awt.Dimension(10, 26));
        textValorTotal.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                textValorTotalFocusLost(evt);
            }
        });

        textDtOrcamento.setBackground(java.awt.Color.white);
        textDtOrcamento.setEditable(false);
        try {
            textDtOrcamento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        textDtOrcamento.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        textDtOrcamento.setFocusLostBehavior(javax.swing.JFormattedTextField.COMMIT);
        textDtOrcamento.setFont(new java.awt.Font("SansSerif", 0, 12));

        textNumOrc.setBackground(java.awt.Color.white);
        textNumOrc.setEditable(false);
        textNumOrc.setFont(new java.awt.Font("SansSerif", 0, 12));
        textNumOrc.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        textNumOrc.setPreferredSize(new java.awt.Dimension(10, 26));

        textNumOrcFornc.setBackground(java.awt.Color.white);
        textNumOrcFornc.setEditable(false);
        textNumOrcFornc.setFont(new java.awt.Font("SansSerif", 0, 12));
        textNumOrcFornc.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        textNumOrcFornc.setPreferredSize(new java.awt.Dimension(10, 26));

        textDtValidade.setBackground(java.awt.Color.white);
        textDtValidade.setEditable(false);
        try {
            textDtValidade.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        textDtValidade.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        textDtValidade.setFocusLostBehavior(javax.swing.JFormattedTextField.COMMIT);
        textDtValidade.setFont(new java.awt.Font("SansSerif", 0, 12));

        btnFornecedor.setFont(new java.awt.Font("SansSerif", 0, 12));
        btnFornecedor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/open.png"))); // NOI18N
        btnFornecedor.setBorderPainted(false);
        btnFornecedor.setContentAreaFilled(false);
        btnFornecedor.setEnabled(false);
        btnFornecedor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnFornecedorMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
        panel.setLayout(panelLayout);
        panelLayout.setHorizontalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(panelLayout.createSequentialGroup()
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbFornecedor)
                            .addComponent(lbValorTotal))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelLayout.createSequentialGroup()
                                .addComponent(textFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 419, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnFornecedor))
                            .addComponent(textValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(panelLayout.createSequentialGroup()
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbNumOrcFunc)
                            .addComponent(lbNumOrcamento))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textNumOrcFornc, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textNumOrc, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbDataOrcamento)
                            .addComponent(lbDataValidade))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(textDtValidade, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textDtOrcamento, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        panelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {textDtValidade, textNumOrc, textNumOrcFornc});

        panelLayout.setVerticalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelLayout.createSequentialGroup()
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbNumOrcamento)
                            .addComponent(textDtOrcamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbDataOrcamento)
                            .addComponent(textNumOrc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbNumOrcFunc)
                            .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lbDataValidade)
                                .addComponent(textDtValidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(panelLayout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(textNumOrcFornc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelLayout.createSequentialGroup()
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lbFornecedor))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbValorTotal)
                            .addComponent(textValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(btnFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        panelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {textDtOrcamento, textDtValidade, textFornecedor, textNumOrc, textNumOrcFornc, textValorTotal});

        panelBotao.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, java.awt.Color.gray));
        panelBotao.setFont(new java.awt.Font("DejaVu Sans", 0, 12));

        btnBuscar.setFont(new java.awt.Font("SansSerif", 0, 10));
        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/find.png"))); // NOI18N
        btnBuscar.setText("Procurar");
        btnBuscar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnBuscarMouseClicked(evt);
            }
        });

        btnNovo.setFont(new java.awt.Font("SansSerif", 0, 10));
        btnNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/new.png"))); // NOI18N
        btnNovo.setText("Novo     ");
        btnNovo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnNovoMouseClicked(evt);
            }
        });

        btnCancel.setFont(new java.awt.Font("SansSerif", 0, 10));
        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cancel.png"))); // NOI18N
        btnCancel.setText("Cancelar");
        btnCancel.setMaximumSize(new java.awt.Dimension(92, 34));
        btnCancel.setMinimumSize(new java.awt.Dimension(92, 34));
        btnCancel.setPreferredSize(new java.awt.Dimension(92, 34));
        btnCancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnCancelMouseClicked(evt);
            }
        });

        btnExcluir.setFont(new java.awt.Font("SansSerif", 0, 10));
        btnExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/delete.png"))); // NOI18N
        btnExcluir.setText("Excluir   ");
        btnExcluir.setMaximumSize(new java.awt.Dimension(92, 34));
        btnExcluir.setMinimumSize(new java.awt.Dimension(92, 34));
        btnExcluir.setPreferredSize(new java.awt.Dimension(92, 34));
        btnExcluir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnExcluirMouseClicked(evt);
            }
        });

        jPanelNavegacao.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btnFirst.setFont(new java.awt.Font("SansSerif", 0, 12));
        btnFirst.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/first.png"))); // NOI18N
        btnFirst.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        btnFirst.setContentAreaFilled(false);
        btnFirst.setEnabled(false);
        btnFirst.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnFirstMouseClicked(evt);
            }
        });

        btnPrevious.setFont(new java.awt.Font("SansSerif", 0, 12));
        btnPrevious.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/previous.png"))); // NOI18N
        btnPrevious.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        btnPrevious.setContentAreaFilled(false);
        btnPrevious.setEnabled(false);
        btnPrevious.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnPreviousMouseClicked(evt);
            }
        });

        btnNext.setFont(new java.awt.Font("SansSerif", 0, 12));
        btnNext.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/next.png"))); // NOI18N
        btnNext.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        btnNext.setContentAreaFilled(false);
        btnNext.setEnabled(false);
        btnNext.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnNextMouseClicked(evt);
            }
        });

        btnLast.setFont(new java.awt.Font("SansSerif", 0, 12));
        btnLast.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/last.png"))); // NOI18N
        btnLast.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        btnLast.setContentAreaFilled(false);
        btnLast.setEnabled(false);
        btnLast.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnLastMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelNavegacaoLayout = new javax.swing.GroupLayout(jPanelNavegacao);
        jPanelNavegacao.setLayout(jPanelNavegacaoLayout);
        jPanelNavegacaoLayout.setHorizontalGroup(
            jPanelNavegacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelNavegacaoLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnFirst)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnPrevious)
                .addGap(10, 10, 10)
                .addComponent(btnNext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnLast)
                .addContainerGap())
        );
        jPanelNavegacaoLayout.setVerticalGroup(
            jPanelNavegacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(btnFirst)
            .addComponent(btnPrevious)
            .addComponent(btnNext)
            .addComponent(btnLast)
        );

        javax.swing.GroupLayout panelBotaoLayout = new javax.swing.GroupLayout(panelBotao);
        panelBotao.setLayout(panelBotaoLayout);
        panelBotaoLayout.setHorizontalGroup(
            panelBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotaoLayout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addComponent(btnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(74, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotaoLayout.createSequentialGroup()
                .addContainerGap(228, Short.MAX_VALUE)
                .addComponent(jPanelNavegacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(223, 223, 223))
        );

        panelBotaoLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnBuscar, btnCancel, btnExcluir, btnNovo});

        panelBotaoLayout.setVerticalGroup(
            panelBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(btnBuscar)
                    .addComponent(btnNovo)
                    .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelNavegacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelBotaoLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnBuscar, btnCancel, btnExcluir, btnNovo});

        btnBuscar.getAccessibleContext().setAccessibleName(null);
        btnNovo.getAccessibleContext().setAccessibleName(null);
        btnCancel.getAccessibleContext().setAccessibleName(null);
        btnExcluir.getAccessibleContext().setAccessibleName(null);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(panel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE)
                    .addComponent(panelBotao, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(17, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBotao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-634)/2, (screenSize.height-303)/2, 634, 303);
    }// </editor-fold>//GEN-END:initComponents

    // Fecha formulario
    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        this.setVisible(false);
        if(this.situacao == K_FORM_CADASTRO){
            this.dispose();
        }
    }//GEN-LAST:event_formWindowClosed

    //<editor-fold defaultstate="collapsed" desc="Busca de Fornecedores">   
    // Realiza a busca do fornecedor
    private void btnFornecedorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnFornecedorMouseClicked
        if(btnFornecedor.isEnabled()){

            FormFornecedor form = new FormFornecedor(FormFornecedor.K_FORM_PESQUISA);
            form.setModal(true);
            form.setVisible(true);

            this.fornecedor = new Pessoa();
            this.fornecedor = form.getFornecedor();
            form.dispose();
            this.textFornecedor.setText(this.fornecedor != null ?
                                                this.fornecedor.getNome() : "");
        }

    }//GEN-LAST:event_btnFornecedorMouseClicked
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Eventos CRUD ">
    /**
     * Responsavel por criar um novo objeto unidade ou salva-lo. Dependendo
     * do estado do atual do botao.
     */
    private void btnNovoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnNovoMouseClicked
        try{
            if(btnNovo.isEnabled()){
                // Verifica o estado do botao
                if(this.btnNovo.getText().startsWith("Novo")){
                    clearFields(); // Limpa o formulario
                    StateMachineButton.changeState(getLstButton(1),
                                                       StateMachineButton.NOVO);
                    StateMachineNavigator.changeState(getLstButton(2),
                                                  StateMachineNavigator.PADRAO);

                    // Cria uma novo orcamento e seta os campos para edicao
                    this.orcamento = new Orcamento();
                    enableFields(K_FIELDS_NOVO);
                    Integer cod = (this.orcamento.recUltCodigo() + 1);
                    this.textNumOrc.setText(cod.toString());
                    this.textValorTotal.setText("0.00");
                }
                else{
                    // Verifica se todos os campos foram mapeados com sucesso
                    if(mapFields(K_FIELDS_NOVO)){

                        boolean flag = false;
                        this.orcamento.setSituacao(StatusOrcamento.PENDENTE);

                        // Verifica se e um novo orcamento ou se apenas para atulizar
                        if(this.orcamento.isNew()){
                            flag = this.orcamento.insert();

                            if(flag){
                                this.lstObj = null;
                                StateMachineButton.changeState(getLstButton(1),
                                                     StateMachineButton.SALVAR);
                            }
                        }
                        else{
                            flag = this.orcamento.update();

                            if(flag){
                                mudarEstadoNavegacao();
                                StateMachineButton.changeState(getLstButton(1),
                                                   StateMachineButton.CANCELAR);
                            }
                        }

                        // Verifica se foi inserido com sucesso no banco de dados
                        if(flag){
                            this.orcamento.setIsNew(false);
                            enableFields(K_FIELDS_SALVAR);

                            // Exibe formulario de itens
                            showFormItem(FormItem.K_FORM_CADASTRO);
                        }
                        else{
                            showMessageError(orcamento.getErrorMessage());
                        }
                    }
                    else{
                        showMessageError(ErrorMessage.MSG_GERAL_OBRIG);
                    }
                }
            }
        }
        catch(IOException ex){ }
    }//GEN-LAST:event_btnNovoMouseClicked
   
    /**
     * Busca e recupera uma lista de orcamentos com os filtros informados
     */
    private void btnBuscarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnBuscarMouseClicked
        try{
            if(btnBuscar.isEnabled()){
                // Verifica o estado do botao
                if(this.btnBuscar.getText().startsWith("Procurar")){
                    clearFields(); // Limpa o formulario

                    StateMachineButton.changeState(getLstButton(1),
                                                   StateMachineButton.PROCURAR);

                    StateMachineNavigator.changeState(getLstButton(2),
                                                  StateMachineNavigator.PADRAO);
                    // Seta os campos como editaveis
                    enableFields(K_FIELDS_BUSCA);
                    this.orcamento = new Orcamento();
                    this.fornecedor = null;
                }
                else{
                    // cria uma nova lista de orcamentos
                    this.lstObj = new ArrayList();
                    mapFields(K_FIELDS_BUSCA);
                    /**
                     * Verifica de que forma a busca sera realizada. A principio
                     * a mesma tera como prioridade o numero informado, caso nao
                     * tenha sido fornecido um numero a busca sera realizada
                     * para os demais campos.
                     */
                    if(this.orcamento.getNumOrcamento() != null ){
                        orcamento = orcamento.refresh(orcamento.getNumOrcamento());

                        // Verifica se foi retornado algum objeto
                        if(orcamento != null)  lstObj.add(orcamento);
                    }
                    else{
                        lstObj = this.orcamento.recLstOrcamentos(this.orcamento);
                    }

                    // Verifica se foi recuperado algum objeto
                    if(lstObj != null && lstObj.size() > 0){
                        enableFields(K_FIELDS_SALVAR);

                        StateMachineNavigator.changeState(getLstButton(2),
                         lstObj.size() == 1 ?
                             StateMachineNavigator.PADRAO :
                             StateMachineNavigator.PRIMEIRO);

                        StateMachineButton.changeState(getLstButton(1),
                                StateMachineButton.RECUPERAR);

                        // Apresenta o primeiro orcamento
                        mostraOrcamento((Orcamento)lstObj.get(0));
                    }
                    else{
                        if(this.orcamento != null){
                            if(!orcamento.getErrorMessage().equals(""))
                                showMessageError(orcamento.getErrorMessage());
                            else
                                showMessageWarning(ErrorMessage.MSG_ORCAMENTO_BUSCA);
                        }
                        else{
                            this.orcamento = new Orcamento();
                            showMessageWarning(ErrorMessage.MSG_ORCAMENTO_BUSCA);
                        }
                    }
                }
            }
        }
        catch(IOException ex){}
    }//GEN-LAST:event_btnBuscarMouseClicked

    /**
     * Cancela uma acao corrente de insercao ou edicao. Responsavel tambem por
     * abrir um registro para edicao.
     */
    private void btnCancelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCancelMouseClicked
        try{
            if(btnCancel.isEnabled()){
                // Verifica o estado do botao
                if(this.btnCancel.getText().startsWith("Cancelar")){

                    // Realiza a confirmacao da acao pelo usuario
                    if(JOptionPane.showConfirmDialog(this, "Confirma o cancelam"
                         +"ento?", "Confirmation", JOptionPane.OK_CANCEL_OPTION,
                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION){

                        enableFields(K_FIELDS_SALVAR); // Desabilita os campos

                        if(this.orcamento.isNew()){
                            clearFields();
                            StateMachineButton.changeState(getLstButton(1),
                                                    StateMachineButton.INICIAL);
                        }
                        else{
                            StateMachineButton.changeState(getLstButton(1),
                                                   StateMachineButton.CANCELAR);
                            mudarEstadoNavegacao();
                        }
                    }
                }
                else{
                    /**
                     * Somente os orcamentos que nao foram transformados em
                     * orcamento podem ser editados uma vez confirmados o evento
                     * chama o formulario de itens somente leitura
                     */

                    if(orcamento.getSituacao() != StatusOrcamento.CONFIRMADO){
                        enableFields(K_FIELDS_NOVO);
                        this.orcamento.setWasUpdated(true);
                        StateMachineButton.changeState(getLstButton(1),
                                                     StateMachineButton.EDITAR);
                        StateMachineNavigator.changeState(getLstButton(2),
                                                  StateMachineNavigator.PADRAO);
                    }
                    else{
                        // Exibe formulario de itens
                        showFormItem(FormItem.K_FORM_EXIBICAO);
                    }
                }
            }
        }
        catch(Exception ex){ }
    }//GEN-LAST:event_btnCancelMouseClicked
    
    /**
     * Exclui um orcamento da base de dados
     */
    private void btnExcluirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnExcluirMouseClicked
        try{
            if(btnExcluir.isEnabled()){
                // Verifica se o orcamento nao foi utilizado em vendas
                if(this.orcamento.getSituacao() != StatusOrcamento.CONFIRMADO){
                    // Realiza a confirmacao da acao pelo usuario
                    if(JOptionPane.showConfirmDialog(this, "Confirma a exclusão?",
                           "Confirmation", JOptionPane.OK_CANCEL_OPTION,
                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION){

                        boolean flag = this.orcamento.delete();
                        if(flag){
                            clearFields();

                            enableFields(K_FIELDS_SALVAR); // Desabilita os campos

                            // Verifica o tamanho da lista
                            if(lstObj != null){
                                // Remove o item da lista corrente
                                lstObj.remove(this.posicao);

                                // Posiciona na base de navegacao
                                mudarEstadoNavegacao();

                                if(lstObj.isEmpty()){
                                    StateMachineButton.changeState(getLstButton(1),
                                                    StateMachineButton.EXCLUIR);
                                }
                                else{
                                    StateMachineButton.changeState(getLstButton(1),
                                                   StateMachineButton.CANCELAR);
                                }
                            }
                            else{
                                StateMachineButton.changeState(getLstButton(1),
                                                    StateMachineButton.EXCLUIR);
                            }
                        }
                        else{
                            showMessageError(orcamento.getErrorMessage());
                        }
                    }
                }
                else{
                    showMessageError(ErrorMessage.MSG_ORCAMENTO_EXCLUSAO);
                }
            }
        }
        catch(Exception ex){ }
    }//GEN-LAST:event_btnExcluirMouseClicked
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Barra Navegacao">
    /**
     * Move para a primeira posicao da lista de orcamentos
     */
    private void btnFirstMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnFirstMouseClicked
        try{
            // Verifica o tamanho da lista de orcamentos
            if(!lstObj.isEmpty() && lstObj.size() > 0 && btnFirst.isEnabled()){

                // Posiciona na posicao inicial
                StateMachineNavigator.changeState(getLstButton(2),
                                                StateMachineNavigator.PRIMEIRO);
                this.posicao = 0;
                mostraOrcamento((Orcamento)lstObj.get(this.posicao));
            }
        }
        catch(Exception ex){ }
    }//GEN-LAST:event_btnFirstMouseClicked

    /**
     * Move para a ultima posicao da lista de orcamentos
     */
    private void btnLastMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnLastMouseClicked
        try{
            // Verifica o tamanho da lista de orcamentos
            if(!lstObj.isEmpty() && lstObj.size() > 0 && btnLast.isEnabled()){

                // Posiciona na posicao final
                StateMachineNavigator.changeState(getLstButton(2),
                                                StateMachineNavigator.ULTIMO);
                this.posicao = lstObj.size() - 1;
                mostraOrcamento((Orcamento)lstObj.get(this.posicao));
            }
        }
        catch(Exception ex){ }
    }//GEN-LAST:event_btnLastMouseClicked

    /**
     * Posiciona na posicao anterior da lista
     */
    private void btnPreviousMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnPreviousMouseClicked
        try{
            // Verifica o tamanho da lista de orcamentos
            if(!lstObj.isEmpty() && lstObj.size() > 0 && btnPrevious.isEnabled()){

                this.posicao--; // Recebe a proxima posicao

                if(this.posicao >= 1){
                    StateMachineNavigator.changeState(getLstButton(2),
                                          StateMachineNavigator.ANTERIOR_MAIOR);
                }
                else{
                    StateMachineNavigator.changeState(getLstButton(2),
                                          StateMachineNavigator.ANTERIOR_MENOR);
                }

                mostraOrcamento((Orcamento)lstObj.get(this.posicao));
            }
        }
        catch(Exception ex){ }
    }//GEN-LAST:event_btnPreviousMouseClicked

    /**
     * Move para a proxima unidade da lista de orcamentos
     */
    private void btnNextMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnNextMouseClicked
        try{
            // Verifica o tamanho da lista de orcametnos
            if(!lstObj.isEmpty() && lstObj.size() > 0 && btnNext.isEnabled()){

                this.posicao++; // Recebe a proxima posicao

                if(this.posicao >= (lstObj.size() - 1)){
                    StateMachineNavigator.changeState(getLstButton(2),
                                          StateMachineNavigator.PROXIMO_MENOR);
                }
                else{
                    StateMachineNavigator.changeState(getLstButton(2),
                                          StateMachineNavigator.PROXIMO_MAIOR);
                }

                mostraOrcamento((Orcamento)lstObj.get(this.posicao));
            }
        }
        catch(Exception ex){ }
    }//GEN-LAST:event_btnNextMouseClicked
    //</editor-fold>

    private void textValorTotalFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_textValorTotalFocusLost
        try{
            if(textValorTotal.isEnabled() &&
                                textValorTotal.getText().trim().length() > 0){
                DecimalFormat format = new DecimalFormat("0.00");

                textValorTotal.setText(format.format(
                Double.parseDouble(
                                  textValorTotal.getText())).replace(',', '.'));
            }
        }
        catch(Exception ex){
            showMessageWarning(ErrorMessage.MSG_GERAL_FORMAT);
        }
    }//GEN-LAST:event_textValorTotalFocusLost

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnFirst;
    private javax.swing.JButton btnFornecedor;
    private javax.swing.JButton btnLast;
    private javax.swing.JButton btnNext;
    private javax.swing.JButton btnNovo;
    private javax.swing.JButton btnPrevious;
    private javax.swing.JPanel jPanelNavegacao;
    private javax.swing.JLabel lbDataOrcamento;
    private javax.swing.JLabel lbDataValidade;
    private javax.swing.JLabel lbFornecedor;
    private javax.swing.JLabel lbNumOrcFunc;
    private javax.swing.JLabel lbNumOrcamento;
    private javax.swing.JLabel lbValorTotal;
    private javax.swing.JPanel panel;
    private javax.swing.JPanel panelBotao;
    private javax.swing.JFormattedTextField textDtOrcamento;
    private javax.swing.JFormattedTextField textDtValidade;
    private javax.swing.JTextField textFornecedor;
    private javax.swing.JTextField textNumOrc;
    private javax.swing.JTextField textNumOrcFornc;
    private javax.swing.JTextField textValorTotal;
    // End of variables declaration//GEN-END:variables

    //<editor-fold defaultstate="collapsed" desc="Methods">
    // Messagem de erro
    private void showMessageError(String msg){
        JOptionPane.showMessageDialog(this, msg, "Orçamento",
                                                    JOptionPane.ERROR_MESSAGE);
    }

    // Messagem de alerta
    private void showMessageWarning(String msg){
        JOptionPane.showMessageDialog(this, msg, "Orçamento",
                                                   JOptionPane.WARNING_MESSAGE);
    }

    private void showFormItem(int tipo){
        FormItem form = new FormItem(tipo, FormItem.K_FORM_ORCAMENTO,
                               orcamento.getCod_objeto(), orcamento.getValor());
        form.setModal(true);
        form.setVisible(true);

        orcamento.setSituacao(
              form.getInserted() ? StatusOrcamento.ABERTO : orcamento.getSituacao());

        form.dispose();
    }

    // Recupera a lista de botoes do formulario
    private ArrayList<JButton> getLstButton(Integer situacao){
        ArrayList<JButton> lstButton = new ArrayList<JButton>();

        if(situacao == 1){
            lstButton.add(this.btnBuscar);
            lstButton.add(this.btnNovo);
            lstButton.add(this.btnCancel);
            lstButton.add(this.btnExcluir);
        }
        else{
            lstButton.add(this.btnFirst);
            lstButton.add(this.btnPrevious);
            lstButton.add(this.btnNext);
            lstButton.add(this.btnLast);
        }

        return lstButton;
    }

    // Limpa os campos do formulario
    private void clearFields(){
        textDtOrcamento.setText(null);
        textDtValidade.setText(null);
        textFornecedor.setText("");
        textNumOrc.setText("");
        textNumOrcFornc.setText("");
        textValorTotal.setText("");
    }

    // Controle dos campos para edicao
    private void enableFields(int tipo){

        switch(tipo){
            case FormOrcamento.K_FIELDS_BUSCA:{
                textNumOrc.setEditable(true);
                textNumOrcFornc.setEditable(true);
                textDtOrcamento.setEditable(true);
                textDtValidade.setEditable(true);
                textValorTotal.setEditable(false);
                btnFornecedor.setEnabled(true);
                break;
            }
            case FormOrcamento.K_FIELDS_SALVAR:{
                textNumOrc.setEditable(false);
                textNumOrcFornc.setEditable(false);
                textDtOrcamento.setEditable(false);
                textDtValidade.setEditable(false);
                textValorTotal.setEditable(false);
                btnFornecedor.setEnabled(false);
                break;
            }
            default:{
                textNumOrc.setEditable(false);
                textNumOrcFornc.setEditable(true);
                textDtOrcamento.setEditable(true);
                textDtValidade.setEditable(true);
                textValorTotal.setEditable(true);
                btnFornecedor.setEnabled(true);
                break;
            }
        }
    }

    // Transfere os campos para o objeto para persistencia
    private boolean mapFields(int tipo){
        boolean map = true;

        try{
            // Formato padrao das dadas do sistema
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
            sdf.setLenient(false);

            // Uppercase nos campos
            textFornecedor.setText(textFornecedor.getText().toUpperCase());


            // Mapeia os campos
            orcamento.setNumOrcamento(textNumOrc.getText().isEmpty() ?
                            null : Integer.parseInt(textNumOrc.getText()));
            orcamento.setNumOrcFornecedor(textNumOrcFornc.getText().isEmpty() ?
                            0 : Integer.parseInt(textNumOrcFornc.getText()));
            orcamento.setValor(textValorTotal.getText().isEmpty() ?
                     0 : Double.parseDouble(textValorTotal.getText()));
            orcamento.setDtValidade(
                    (!textDtValidade.getText().equals("  /  /    ")) ?
                     new Date(sdf.parse(textDtValidade.getText()).getTime()) :
                                                                          null);
            orcamento.setDtOrcamento(
                    (!textDtOrcamento.getText().equals("  /  /    ")) ?
                     new Date(sdf.parse(textDtOrcamento.getText()).getTime()) :
                                                                          null);

            // Verifica se foi informado algum fornecedor para cadastro
            map = fornecedor != null ? true : false;
            if(map){
                orcamento.setFornecedor(fornecedor.getCod_objeto());
            }
            else{
                // Verifica o estado para mudanca
                map = tipo == K_FIELDS_BUSCA ? true : false;
            }
        }
        catch(Exception ex){
            ex.printStackTrace();
            map = false;
        }
        return map;
    }

    // Realiza a apresentacao das unidades recuperadas no formulario
    private void mostraOrcamento(Orcamento obj){
        // Formato padrao das dadas do sistema
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        DecimalFormat format = new DecimalFormat("0.00");

        orcamento = obj;
        // Apresenta os campos
        textNumOrc.setText(obj.getNumOrcamento().toString());
        textNumOrcFornc.setText(obj.getNumOrcFornecedor() != 0 ? 
                            obj.getNumOrcFornecedor().toString() : "");
        textValorTotal.setText(format.format(obj.getValor()).replace(',', '.'));

        // Recuperando o fornecedor
        fornecedor = new Pessoa();
        fornecedor = fornecedor.refresh(obj.getFornecedor());
        textFornecedor.setText(fornecedor.getNome());

        // Apresenta as datas
        textDtValidade.setText(orcamento.getDtValidade() != null ?
            sdf.format(orcamento.getDtValidade()) : null);
        textDtOrcamento.setText(orcamento.getDtOrcamento() != null ?
            sdf.format(orcamento.getDtOrcamento()) : null);

        // Desabilita os campos para edicao
        enableFields(K_FIELDS_SALVAR);
    }

    // Inicializa o estados de todos os botoes
    private void initializeMyComponents(){
        try{
            StateMachineButton.changeState(getLstButton(1),
                                                  StateMachineButton.INICIAL);
            StateMachineNavigator.changeState(getLstButton(2),
                                                  StateMachineNavigator.PADRAO);
            clearFields();
        }
        catch(IOException ex){}
    }

    // Volta ao estado da navegacao
    private void mudarEstadoNavegacao() throws IOException{

        if(lstObj != null){
            // Verifica se existe a posicao na lista
            boolean exists = this.posicao < this.lstObj.size() ? true : false;

            // Decrementa uma posicao caso a ultima tenha sido removida
            if(!exists) this.posicao--;

            // Verifica se a lista esta vazia
            if(lstObj.isEmpty()){
                clearFields();
                StateMachineNavigator.changeState(getLstButton(2),
                                                  StateMachineNavigator.PADRAO);
            }
            // Verifica se o tamanho da lista e 1
            else{
                mostraOrcamento((Orcamento)lstObj.get(this.posicao));

                if(lstObj.size() <= 1){
                    StateMachineNavigator.changeState(getLstButton(2),
                                                  StateMachineNavigator.PADRAO);
                }
                else{
                    // Verifica qual a posicao que se encontra
                    if(this.posicao == 0){
                        StateMachineNavigator.changeState(getLstButton(2),
                                                StateMachineNavigator.PRIMEIRO);
                    }
                    else if(this.posicao == (lstObj.size() - 1)){
                        StateMachineNavigator.changeState(getLstButton(2),
                                                  StateMachineNavigator.ULTIMO);
                    }
                    else{
                        StateMachineNavigator.changeState(getLstButton(2),
                                          StateMachineNavigator.ANTERIOR_MAIOR);
                    }
                }
            }
        }
    }
    //</editor-fold>
}